﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace GalaxyPresident
{
    public abstract class SendTask : Task
    {
        protected Planet source;
        protected Planet target;
        protected MotherShip motherShip;
        public static GalaxyLayer galaxyLayer;
        protected SendingInfo sendingInfo;

        public MotherShip MotherShip
        {
            get { return motherShip; }
            set { motherShip = value; }
        }

        public SendingInfo SendingInfo
        {
            get { return sendingInfo; }
            set { sendingInfo = value; }
        }
        public Planet Source
        {
            get { return source; }
            set { source = value; }
        }
        public Planet Target
        {
            get { return target; }
            set { target = value; }
        }
        public virtual Color GetColor()
        {
            return Color.HotPink;
        }
        public SendTask(Planet sourcePlanet)
        {
            source = sourcePlanet;
        }
        public virtual bool isAvailable(bool isOwner)
        {
            return !isOwner;
        }
        public override bool Execute()
        {
            if (motherShip == null)
                return false;
            motherShip.MotherShipTask = this;
            motherShip.PlanetOwner = null;
            source.Meterial -= sendingInfo.Material;
            source.Energy -= sendingInfo.Enegry;
            List<Unit> units = motherShip.TeamOwner.GetUnitsFromPlanet(sendingInfo.NumberOfUnits, source);
            foreach (Unit unit in units)
            {
                if (unit.Station != null)
                {
                    unit.Station.RemoveUnit(unit);
                }
                motherShip.AddUnit(unit);
            }
            if (motherShip.Parent == null)
            {
                source.AddToLayer(motherShip);
                motherShip.Position = new Vector2(-source.Diameter * 3, -source.Diameter * 3);
            }
            motherShip.moveTo(new Vector2(-source.Diameter * 20, -source.Diameter *20));

            galaxyLayer.AddToLayer(new MotherShipView(motherShip));
            return true;
        }

        public virtual void setCompleteSendTask()
        {
        }
    }
}
